function avg_acc = gogo(X1train, X2train, ytrain, gidtrain, k, algo)
%GOGO Summary of this function goes here
%   Detailed explanation goes here
    avg_acc = 0;
    
    for gid=1:3
        [tr_data, tr_label, te_data, te_label] = ...
            perform_pca(X1train, X2train, ytrain, gidtrain, gid, k);
        
        if strcmp(algo,'svm')
            % for full pca - 2399 attributes result was 64.75%
            e = svmtrain(tr_label, tr_data, '-c 10000 -g 0.00001');
            [~, stats, ~] = svmpredict(te_label, te_data, e, '');
            avg_acc = avg_acc + stats(1);
        elseif strcmp(algo,'ada')
            ada = fitensemble(tr_data,tr_label,'AdaBoostM1',500,'Tree');
            r = ada.predict(te_data);
            avg_acc = avg_acc + sum(te_label==r)/1200 * 100;
            fprintf('Result for group %d as test: %f.\n', gid, sum(te_label==r)/1200*100);
        elseif strcmp(algo,'tree')
            tc = ClassificationTree.fit(tr_data,tr_label, ...
                                        'PruneCriterion', 'impurity', ...
                                        'SplitCriterion', 'deviance');
            r = tc.predict(te_data);
            avg_acc = avg_acc + sum(te_label==r)/1200 * 100;
        elseif strcmp(algo,'treebag')
            % slow for k =100
            b = TreeBagger(500,tr_data,tr_label,'Method','classification');
            r = b.predict(te_data);
            r = cell_str_2_num(r);
            avg_acc = avg_acc + sum(te_label==r)/1200 * 100;
        else
            fprintf('Algorithm: %s is not supported.\n', algo)
        end
    end
    avg_acc = avg_acc / 3;
end

